package com.ehotting.edsta.mqbd.signal.client.config;

import com.ehotting.edsta.mqbd.signal.client.handler.SISendUserServiceAble;
import com.ehotting.mqbd.api.enums.DirectionEnum;
import com.ehotting.mqbd.api.enums.TopicEnum;
import com.ehotting.mqbd.api.bean.MqApplicationContext;
import com.ehotting.mqbd.core.config.MqbdCorePropertyConfig;
import com.ehotting.mqbd.core.helper.MQStringHelper;
import com.ehotting.mqbd.core.logger.MqMsgLogger;
import com.ehotting.mqbd.core.mq.consumer.MessageConsumer;
import com.ehotting.edsta.mqbd.signal.client.handler.SIConsumerResponseAction;
import com.ehotting.mqbd.core.manager.ModuleManager;
import com.ehotting.mqbd.core.sync.MqSyncFutureMapHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
@DependsOn("mqbdCorePropertyConfig")
public class SIConsumerResponseConfig {

    @Bean
    public SIConsumerResponseAction siConsumerResponseAction(SISendUserServiceAble siSendUser,
                                                                MqSyncFutureMapHelper mqSyncFutureMapHelper,
                                                                MqApplicationContext mqApplicationContext,
                                                                ModuleManager moduleManager,
                                                                MqMsgLogger mqMsgLogger){
        SIConsumerResponseAction handler = new SIConsumerResponseAction(
                mqSyncFutureMapHelper,
                mqApplicationContext,
                TopicEnum.CONCURRENCY,
                DirectionEnum.RESPONSE,
                null,
                moduleManager,
                mqMsgLogger);
        handler.setSiSendUser(siSendUser);
        return handler;
    }

    @Bean(name="siConcurrencyResponseMessageConsumer",initMethod = "start",destroyMethod = "shutdown")
    public MessageConsumer siConcurrencyResponseMessageConsumer(MqbdCorePropertyConfig mqbdCorePropertyConfig,
                                                                SIConsumerResponseAction siConsumerResponseAction,
                                                                MqApplicationContext mqApplicationContext){
        MessageConsumer messageConsumer = new MessageConsumer(
                mqbdCorePropertyConfig.getConsumer(),
                MQStringHelper.createConsumerGroupAtConsumerApp(TopicEnum.CONCURRENCY,
                        mqApplicationContext,
                        DirectionEnum.RESPONSE),
                siConsumerResponseAction);
        return messageConsumer;
    }

}